package cn.edu.sdjzu.xg.eagle.bysj.controller;

import cn.edu.sdjzu.xg.eagle.bysj.annotation.IgnoreAuth;
import cn.edu.sdjzu.xg.eagle.bysj.annotation.SysLog;
import cn.edu.sdjzu.xg.eagle.bysj.entity.YuangongchuchashenqingEntity;
import cn.edu.sdjzu.xg.eagle.bysj.entity.view.YuangongchuchashenqingView;
import cn.edu.sdjzu.xg.eagle.bysj.service.Interface.YuangongchuchashenqingService;
import cn.edu.sdjzu.xg.eagle.bysj.utils.MPUtil;
import cn.edu.sdjzu.xg.eagle.bysj.utils.PageUtils;
import cn.edu.sdjzu.xg.eagle.bysj.utils.R;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 员工出差申请
 * 后端接口
 * @author 
 * @email 
 * @date 2025-06-02 13:29:29
 */
@RestController
@RequestMapping("/yuangongchuchashenqing")
public class YuangongchuchashenqingController {
    @Autowired
    private YuangongchuchashenqingService yuangongchuchashenqingService;









    /**
     * 后台列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, YuangongchuchashenqingEntity yuangongchuchashenqing,
                  HttpServletRequest request){
                    String tableName = request.getSession().getAttribute("tableName").toString();
                                            if(tableName.equals("yuangong")) {
                    yuangongchuchashenqing.setYuangonggonghao((String)request.getSession().getAttribute("username"));
                                    }
                                                                                                                                                                                                                                                                                                                                                        EntityWrapper<YuangongchuchashenqingEntity> ew = new EntityWrapper<YuangongchuchashenqingEntity>();
                                                                                                                                                                                                                                                                
        
        
        PageUtils page = yuangongchuchashenqingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yuangongchuchashenqing), params), params));
        return R.ok().put("data", page);
    }







    /**
     * 前端列表
     */
	@IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,YuangongchuchashenqingEntity yuangongchuchashenqing,
		HttpServletRequest request){
        EntityWrapper<YuangongchuchashenqingEntity> ew = new EntityWrapper<YuangongchuchashenqingEntity>();

		PageUtils page = yuangongchuchashenqingService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, yuangongchuchashenqing), params), params));
        return R.ok().put("data", page);
    }

	/**
     * 列表
     */
    @RequestMapping("/lists")
    public R list( YuangongchuchashenqingEntity yuangongchuchashenqing){
       	EntityWrapper<YuangongchuchashenqingEntity> ew = new EntityWrapper<YuangongchuchashenqingEntity>();
      	ew.allEq(MPUtil.allEQMapPre( yuangongchuchashenqing, MPUtil.camelToSnake("yuangongchuchashenqing")));
        return R.ok().put("data", yuangongchuchashenqingService.selectListView(ew));
    }

	 /**
     * 查询
     */
    @RequestMapping("/query")
    public R query(YuangongchuchashenqingEntity yuangongchuchashenqing){
        EntityWrapper< YuangongchuchashenqingEntity> ew = new EntityWrapper< YuangongchuchashenqingEntity>();
 		ew.allEq(MPUtil.allEQMapPre( yuangongchuchashenqing, MPUtil.camelToSnake("yuangongchuchashenqing")));
		YuangongchuchashenqingView yuangongchuchashenqingView =  yuangongchuchashenqingService.selectView(ew);
		return R.ok("查询员工出差申请成功").put("data", yuangongchuchashenqingView);
    }
	
    /**
     * 后端详情
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
        YuangongchuchashenqingEntity yuangongchuchashenqing = yuangongchuchashenqingService.selectById(id);
		yuangongchuchashenqing = yuangongchuchashenqingService.selectView(new EntityWrapper<YuangongchuchashenqingEntity>().eq("id", id));
        return R.ok().put("data", yuangongchuchashenqing);
    }

    /**
     * 前端详情
     */
	@IgnoreAuth
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Long id){
        YuangongchuchashenqingEntity yuangongchuchashenqing = yuangongchuchashenqingService.selectById(id);
		yuangongchuchashenqing = yuangongchuchashenqingService.selectView(new EntityWrapper<YuangongchuchashenqingEntity>().eq("id", id));
        return R.ok().put("data", yuangongchuchashenqing);
    }
    



    /**
     * 后端保存
     */
    @RequestMapping("/save")
    @SysLog("新增员工出差申请")
    public R save(@RequestBody YuangongchuchashenqingEntity yuangongchuchashenqing, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(yuangongchuchashenqing);
        yuangongchuchashenqingService.insert(yuangongchuchashenqing);
        return R.ok();
    }
    
    /**
     * 前端保存
     */
    @SysLog("新增员工出差申请")
    @RequestMapping("/add")
    public R add(@RequestBody YuangongchuchashenqingEntity yuangongchuchashenqing, HttpServletRequest request){
    	//ValidatorUtils.validateEntity(yuangongchuchashenqing);
        yuangongchuchashenqingService.insert(yuangongchuchashenqing);
        return R.ok();
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    @Transactional
    @SysLog("修改员工出差申请")
    public R update(@RequestBody YuangongchuchashenqingEntity yuangongchuchashenqing, HttpServletRequest request){
        //ValidatorUtils.validateEntity(yuangongchuchashenqing);
        yuangongchuchashenqingService.updateById(yuangongchuchashenqing);//全部更新
        return R.ok();
    }

    /**
     * 审核
     */
    @RequestMapping("/shBatch")
    @Transactional
    @SysLog("审核员工出差申请")
    public R update(@RequestBody Long[] ids, @RequestParam String sfsh, @RequestParam String shhf){
        List<YuangongchuchashenqingEntity> list = new ArrayList<YuangongchuchashenqingEntity>();
        for(Long id : ids) {
            YuangongchuchashenqingEntity yuangongchuchashenqing = yuangongchuchashenqingService.selectById(id);
            yuangongchuchashenqing.setSfsh(sfsh);
            yuangongchuchashenqing.setShhf(shhf);
            list.add(yuangongchuchashenqing);
        }
        yuangongchuchashenqingService.updateBatchById(list);
        return R.ok();
    }


    

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @SysLog("删除员工出差申请")
    public R delete(@RequestBody Long[] ids){
        yuangongchuchashenqingService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

    	









}
